<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取样式</title>
    <style>
        .test {
            max-width: 200px;
            max-height: 200px;
            border: 1px solid #dedede;
            margin: auto;
            font-size: 16px;
            text-align: center;
            border-radius: 8px;
            cursor: pointer;
            color:rgba(0,0,0.85);
            padding: 20px;
        }
    </style>
</head>
<body>
    <div class="test" id="test">请点击我获取样式属性</div>
    <script>
        const getStyle = (el,ruleName) => getComputedStyle(el)[ruleName];
        const test = document.querySelector("#test");
        test.addEventListener("click",() => {
            alert('属性名:width,属性值:' + getStyle(test,'width'));
        })
    </script>
</body>
</html>